﻿using Microsoft.Extensions.Logging;
using Quartz;
using System.Threading.Tasks;
using System;
using SportsPlatform.Global;

namespace SportsPlatform.Web.Host.FrameworkQuartz
{
    [DisallowConcurrentExecution]
    public class UldAdminFrameworkJob : IJob
    {
        private readonly ILogger<UldAdminFrameworkJob> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger"></param>
        public UldAdminFrameworkJob(ILogger<UldAdminFrameworkJob> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 执行框架作业
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task Execute(IJobExecutionContext context)
        {
            String time = DateTime.Now.ToString("HH:mm");
            if (time.Equals("04:00"))
            {
                //清理临时文件、释放服务器存储空间
                UldFileContext.ClearDirectory(UldAdminGlobalContext.DirectoryConfig.GetTempPath());
            }

            _logger.LogInformation("体趣管理平台任务已执行");

            return Task.CompletedTask;
        }
    }
}
